import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:high_help_apps/common/values/colors.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:high_help_apps/common/widgets/common/evaluation_widget/evaluation_card.dart';
import 'package:high_help_apps/common/widgets/common/evaluation_widget/evaluation_introduction.dart';

import 'user_fav_profile_logic.dart';
import 'user_fav_profile_state.dart';

class UserFavProfilePage extends StatefulWidget {
  @override
  _UserFavProfilePageState createState() => _UserFavProfilePageState();
}

class _UserFavProfilePageState extends State<UserFavProfilePage> {
  final UserFavProfileLogic logic = Get.put(UserFavProfileLogic());
  final UserFavProfileState state = Get.find<UserFavProfileLogic>().state;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        body: Container(
      decoration: BoxDecoration(
          image: DecorationImage(
              image: NetworkImage(
                'https://c-ssl.duitang.com/uploads/item/201809/30/20180930212927_huohk.thumb.1000_0.jpg',
                //'https://uploadfile.bizhizu.cn/up/25/8a/a2/258aa2ed6193f0ed78f78b490f476e43.jpg',
              ),
              fit: BoxFit.cover)),
      child: CustomScrollView(
        physics: NeverScrollableScrollPhysics(),
        slivers: [_buildSliverAppBar(), _buildProfileBox()],
      ),
    ));
  }

  List<Widget> _buildActions() => <Widget>[
        IconButton(
          onPressed: () {
            print('点击了更多');
          },
          icon: Icon(
            Icons.more_horiz,
            color: AppColors.userBarWhite,
          ),
        )
      ];

  Widget _buildSliverAppBar() => SliverAppBar(
        expandedHeight: 400.h,
        actions: _buildActions(),
        elevation: 0,
        pinned: true,
        backgroundColor: Colors.transparent,
        iconTheme: IconThemeData(color: Colors.white),
        flexibleSpace: FlexibleSpaceBar(
          // 伸展处布局
          collapseMode: CollapseMode.parallax,
          // background: Image.network(
          //   'https://uploadfile.bizhizu.cn/up/25/8a/a2/258aa2ed6193f0ed78f78b490f476e43.jpg',
          //   fit: BoxFit.cover,
          // ),
        ),
      );

  Widget _buildProfileBoxIntroduction() => Padding(
        padding: EdgeInsets.all(5.r),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Text(
              '南风微凉',
              style: TextStyle(
                  fontSize: 30.sp,
                  fontWeight: FontWeight.bold,
                  color: Colors.white),
            ),
            SizedBox(
              height: 12.5.h,
            ),
            Text(
              '山东理工大学计算机科学与技术学院',
              style: TextStyle(fontSize: 12.5.sp, color: Colors.white),
            )
          ],
        ),
      );

  Widget _buildProfileEvaluationCard() => EvaluationCard(
        evaluationData: [
          EvaluationIntroduction(content: '125', introduction: '作品'),
          EvaluationIntroduction(content: '250', introduction: '粉丝'),
          EvaluationIntroduction(content: '1256', introduction: 'TA的关注'),
        ],
        backgroundColor: Colors.transparent,
        titleColor: Colors.white,
        subtitleColor: AppColors.subTextColor,
        isScroll: false,
      );

  Widget _buildFollowButton() => Material(
        color: Colors.transparent,
        child: Ink(
          decoration: BoxDecoration(
            color: Color.fromRGBO(100, 120, 211, 1.00),
            borderRadius: BorderRadius.all(Radius.circular(50.r)),
          ),
          child: InkWell(
            onTap: () {},
            borderRadius: BorderRadius.all(Radius.circular(50.r)),
            child: Container(
              width: double.infinity,
              height: 45.h,
              child: Center(
                child: Text(
                  '关注TA',
                  style: TextStyle(color: Colors.white, fontSize: 16.sp),
                ),
              ),
            ),
          ),
        ),
      );

  Widget _buildProfileBox() => SliverToBoxAdapter(
          child: Container(
        alignment: AlignmentDirectional.topStart,
        padding: EdgeInsets.all(25.r),
        decoration: BoxDecoration(
          borderRadius: BorderRadius.only(
            topLeft: Radius.circular(50.r),
            topRight: Radius.circular(50.r),
          ),
          boxShadow: [
            BoxShadow(
                color: Colors.black26,
                offset: Offset(0.0, 15.0),
                blurRadius: 15.0,
                spreadRadius: 5.0),
            BoxShadow(
                color: Colors.black54,
                offset: Offset(0.0, 20.0),
                blurRadius: 25.0,
                spreadRadius: 15.0)
          ],
        ),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            _buildProfileBoxIntroduction(),
            _buildProfileEvaluationCard(),
            _buildFollowButton()
          ],
        ),
      ));

  @override
  void dispose() {
    Get.delete<UserFavProfileLogic>();
    super.dispose();
  }
}
